#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import rospy

import json
from flask import Blueprint, request, Response

from parser.navgation_parser import Navgation_Parser
from tool.common import *

navgation_parser = Navgation_Parser()
navgation_server = Blueprint("/navgation",__name__)

#---------------------------------#
#******#   flask-网络端口验证   #******#
#---------------------------------#
@navgation_server.before_request
def before():
    res_data = before_user(request)
    if res_data:
        return Response(json.dumps(res_data),  mimetype='application/json')

#---------------------------------#
    #******#   POST   #******#
#---------------------------------#
# 开始运动到目标点
# req: 
# res: 
@navgation_server.route('/point_moveto',methods=['POST'])
def Post_SetMovetoPoint():
    data = request.json
    res_data = navgation_parser.SetMovetoPoint(data)
    return Response(json.dumps(res_data),  mimetype='application/json')

#---------------------------------#
    #******#   POST   #******#
#---------------------------------#
# 取消运动到目标点
# req: 
# res: 
@navgation_server.route('/point_cancel',methods=['POST'])
def Post_CancelMovetoPoint():
    res_data = navgation_parser.CancelMovetoPoint()
    return Response(json.dumps(res_data),  mimetype='application/json')

#---------------------------------#
    #******#   POST   #******#
#---------------------------------#
# 开始回桩充电
# req: 
# res: 
@navgation_server.route('/go_home',methods=['POST'])
def Post_SetGoHome():
    res_data = navgation_parser.SetGoHome()
    return Response(json.dumps(res_data),  mimetype='application/json')

#---------------------------------#
    #******#   POST   #******#
#---------------------------------#
# 取消回桩充电
# req: 
# res: 
@navgation_server.route('/cancel_go_home',methods=['POST'])
def Post_CancelGoHome():
    res_data = navgation_parser.CancelGoHome()
    return Response(json.dumps(res_data),  mimetype='application/json')

#---------------------------------#
    #******#   POST   #******#
#---------------------------------#
# 退桩操作
# req: 
# res: 
@navgation_server.route('/docker_back',methods=['POST'])
def Post_SetDockerBack():
    res_data = navgation_parser.SetDockerBack()
    return Response(json.dumps(res_data),  mimetype='application/json')


